package com.ihg.hiex.admin.dao.account;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.ihg.hiex.entity.user.Administrator;

/**
 * @author Guangli Yan
 *
 */
@Dao("hibernate")
public interface AdministratorDao {

    /**
     * count administrator by role
     * 
     * @param role
     * @return
     */
    @Query("SELECT COUNT(1) FROM Administrator WHERE disabled = false AND role = :role")
    public int count(@Variable("role") String role);
    
    /**
     * @param role
     * @return
     */
    @Query("FROM Administrator WHERE disabled = false AND role = :role")
    public List<Administrator> list(@Variable("role") String role);
    
    /**
     * list administrator by role
     * 
     * @param role
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Administrator WHERE disabled = false AND role = :role ORDER BY lastModifyTime DESC")
    public List<Administrator> list(@Variable("role") String role, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
	/**
	 * @param email
	 * @param role
	 * @return
	 */
	@Query("FROM Administrator WHERE disabled = false AND email =:email AND role = :role")
	public Administrator loadByEmail(@Variable("email") String email, @Variable("role") String role);
	
}
